package com.kang.commons.interceptor;

import com.kang.commons.exception.MyException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: photo_fawu
 * @description: 异常全局处理
 * @author: K.faWu
 * @create: 2021-11-05 14:12
 **/

/*@ControllerAdvice
@Slf4j*/
public class GlobalExceptionHandler {

    /**
     * 处理系统异常
     *
     * @param ex
     * @return
     */
/*    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public String systemErrorHandler(Exception ex) {
        log.error(ex.getStackTrace().toString());
        Result<String> result = Result.failure("系统异常", ex.getMessage());
        return JSONObject.valueToString(result);
    }

    *//**
     * 处理自定义异常
     */
    @ExceptionHandler(value = MyException.class)
    @ResponseBody
    public String customizeException(MyException ce) {
        return ce.getContent();
    }
}
